<?php
/**
 * Created By PhpStorm
 * Author: patrick wu
 * Date: 2020/9/29
 * Time: 14:47
 */
namespace App\Http\Model\Mysql;

use Illuminate\Database\Eloquent\Model;

class OrderModel extends Model
{
    const IS_DELETE     =   1,      //已删除
          NOT_DELETE    =   0;      //未删除

    const IS_NORMAL     =   1,      //正常订单
        IS_CANCEL       =   2,      //取消订单
        IS_AFTER_SALE   =   3;      //售后订单

    const IS_PAY        =   1,      //已支付
        NOT_PAY         =   0;      //未支付

    const IS_SEND       =   1,      //已发货
        NOT_SEND        =   0;      //未发货

    const IS_CONFIRM    =   1,      //已确认
        NOT_CONFIRM     =   0;      //未确认

    const APPLY_NORMAL  =   1,      //无售后
        APPLY_REFUND    =   2,      //申请退款
        APPLY_RETURN    =   3;      //申请退货

    protected $table    =   'mini_order';

    protected $guarded  =   [];

    protected $dateFormat   =   'U';

    /**
     * 定义连接多个供应商表
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function supply()
    {
        return $this->hasMany(OrderSupplyModel::class, 'order_id', 'id');
    }

    /**
     * 定义连接多产品表
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function product()
    {
        return $this->hasMany(OrderProductModel::class, 'order_id', 'id');
    }

    /**
     * 定义连接订单返佣表
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function commission()
    {
        return $this->hasOne(OrderIncomeModel::class, 'oid', 'id');
    }

    /**
     * 定义连接用户表
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function user()
    {
        return $this->hasOne(UserModel::class, 'id', 'user_id');
    }

    /**
     * 定义连接售后
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function refund()
    {
        return $this->hasMany(OrderRefundModel::class, 'order_id', 'id');
    }
}
